<template>
  <div class="welcom">
    <!-- 时钟 -->
    <div id="clock">
      <p class="date">{{ date }}</p>
      <p class="time">{{ time }}</p>
      <p class="text"></p>
    </div>
    <!-- 用户信息 -->
    <div class="userinfo">
      <img class="avatar" src="http://jiangapi.jx211.cn/jiangimg" alt="" />
      <div class="name">欢迎您:{{ userInfo.user }}!</div>
      <div class="role">角 色:{{ userInfo.role }}</div>
    </div>
    <!-- 名言 -->
    <div class="myspeak">
      <div class="txt">拒绝3分钟热度<br />!</div>
      <div class="no">
        <div class="line"></div>
      </div>
    </div>
    <!-- 轮播 -->
    <div class="image">
      <el-carousel
        trigger="click"
        height="380px"
        :interval="12000"
        @change="imgChange"
        indicator-position="none"
      >
        <el-carousel-item>
          <img src="http://jj.jx211.cn:4399/jiangimg" alt="" />
        </el-carousel-item>
        <el-carousel-item>
          <img
            :src="'http://jiangapi.jx211.cn/jiang%20(' + img1 + ').png'"
            alt=""
          />
        </el-carousel-item>
        <el-carousel-item>
          <img
            :src="'http://jiangapi.jx211.cn/jiang%20(' + img2 + ').png'"
            alt=""
          />
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      time: '',
      date: '',
      //  用户信息
      userInfo: '',
      img1: '8',
      img2: '88'
    }
  },
  mounted () {
    this.setTime()
  },
  methods: {
    // 轮播切换
    imgChange () {
      this.img1 = Math.floor(Math.random() * (2060 - 1 + 1) + 1)
      this.img2 = Math.floor(Math.random() * (2060 - 1 + 1) + 1)
    },
    setTime () {
      let that = this
      var week = [
        '星期日',
        '星期一',
        '星期二',
        '星期三',
        '星期四',
        '星期五',
        '星期六'
      ]
      var timerID = setInterval(updateTime, 1000)
      updateTime()
      function updateTime () {
        var cd = new Date()
        that.time =
          zeroPadding(cd.getHours(), 2) +
          ':' +
          zeroPadding(cd.getMinutes(), 2) +
          ':' +
          zeroPadding(cd.getSeconds(), 2)
        that.date =
          zeroPadding(cd.getFullYear(), 4) +
          '-' +
          zeroPadding(cd.getMonth() + 1, 2) +
          '-' +
          zeroPadding(cd.getDate(), 2) +
          ' ' +
          week[cd.getDay()]
      }

      function zeroPadding (num, digit) {
        var zero = ''
        for (var i = 0; i < digit; i++) {
          zero += '0'
        }
        return (zero + num).slice(-digit)
      }
    }
  },
  async created () {
    this.userInfo = JSON.parse(window.sessionStorage.getItem('userInfo'))
    //  查询用户角色
    if (this.userInfo.rid === 0) {
      this.userInfo.role = '超级管理员'
    } else {
      const { data: res } = await this.$http.get(`roles/${this.userInfo.rid}`)
      if (res.meta.status !== 200) {
        this.userInfo.role = '未知'
      } else {
        this.userInfo.role = res.data.roleName
      }
    }
  }
}
</script>
<style lang="less" scoped>
.welcom {
  position: relative;
  height: 100%;
  width: 100%;
  background: #0f3854;
  background: -webkit-radial-gradient(center ellipse, #0a2e38 0%, #000000 70%);
  background: radial-gradient(ellipse at center, #0a2e38 0%, #000000 70%);
  background-size: 100%;
  overflow: hidden;
}

p {
  margin: 0;
  padding: 0;
}

#clock {
  font-family: 'Share Tech Mono', monospace;
  color: #ffffff;
  text-align: center;
  position: absolute;
  left: 80%;
  top: 20%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  color: #daf6ff;
  text-shadow: 0 0 20px #0aafe6, 0 0 20px rgba(10, 175, 230, 0);
}
#clock .time {
  letter-spacing: 0.05em;
  font-size: 60px;
  padding: 5px 0;
}
#clock .date {
  letter-spacing: 0.1em;
  font-size: 24px;
}
#clock .text {
  letter-spacing: 0.1em;
  font-size: 12px;
  padding: 20px 0 0;
}
.userinfo {
  position: relative;
  height: 180px;
  width: 700px;
  background-color: rgba(255, 255, 255, 0.2);
  margin-top: 20px;
  margin-left: 20px;
  border-radius: 30px;
  .avatar {
    height: 120px;
    width: 120px;
    border-radius: 50%;
    margin-top: 30px;
    margin-left: 50px;
    vertical-align: top;
  }
  .name,
  .role {
    display: inline-block;
    font-family: 'Share Tech Mono', monospace;
    color: #daf6ff;
    text-shadow: 0 0 20px #0aafe6, 0 0 20px rgba(10, 175, 230, 0);
    font-size: 40px;
    font-weight: 600;
    margin-top: 20px;
    margin-left: 70px;
  }
  .role {
    position: absolute;
    bottom: 30px;
    left: 170px;
    width: 400px;
  }
}
.myspeak {
  position: absolute;
  right: 150px;
  height: 400px;
  width: 200px;
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 30px;
  .txt {
    width: 50px;
    color: #fff;
    font-family: 'Share Tech Mono', monospace;
    text-shadow: 0 0 20px #0aafe6, 0 0 20px rgba(10, 175, 230, 0);
    font-size: 40px;
    font-weight: 700;
    margin-top: 10px;
    margin-left: 20px;
    text-align: center;
  }
  .no {
    position: absolute;
    bottom: 50px;
    right: 10px;
    height: 100px;
    width: 100px;
    border-radius: 50%;
    border: 4px solid red;
    margin-bottom: 40px;
    text-align: center;
    line-height: 100px;
    .line {
      position: absolute;
      left: 40px;
      top: 0;
      width: 10px;
      height: 100%;
      background-color: red;
      transform: rotate(-60deg);
    }
  }
}
.image {
  height: 380px;
  width: 700px;
  background-color: #fff;
  margin-left: 20px;
  margin-top: 20px;
  border-radius: 30px;
  overflow: hidden;
  .el-carousel,
  .el-carousel-item,
  img {
    height: 100%;
    width: 100%;
  }
}
</style>
